//
//  UILabel+AttributedString.m
//  KKCategoryKit
//
//  Created by liaozhenming on 16/10/12.
//  Copyright © 2016年 liaozhenming. All rights reserved.
//

#import "UILabel+AttributedString.h"

@implementation UILabel (AttributedString)

- (void)kk_attributedStringWithTitle:(NSString*)title image:(UIImage*)image imageFrame:(CGRect)imageFrame imageLocationIsLeft:(BOOL)left {
    
    if (title == nil) {
        return;
    }
    
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString: title];
    // 添加表情
    NSTextAttachment *attch = [[NSTextAttachment alloc] init];
    // 表情图片
    attch.image = image;
    // 设置图片大小
    attch.bounds = imageFrame;
    // 创建带有图片的富文本
    NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attch];
    if (left) {
        [attributedString insertAttributedString: string atIndex: 0];
    }
    else {
        [attributedString appendAttributedString:string];
    }
    
    self.attributedText = attributedString;
}


@end
